#!/usr/bin/python
# -*- coding: utf-8 -*-
import maya.cmds as mc
import maya.mel as mel
import createVis

class craft_car_rig(createVis.CreateVis):
    def __init__(self):
    
        createVis.CreateVis.__init__(self)
        self.centerWheel = [ ['L_wheel_front_center_templeLoc', (82.546, 33.437, 108.078  ) ] , 
                        ['R_wheel_front_center_templeLoc', (-82.546, 33.437, 108.078  ) ] ,
                        ['L_wheel_back_center_templeLoc', (82.546, 33.437, -132.855 ) ]  , 
                        ['R_wheel_back_center_templeLoc', (-82.546, 33.437, -132.855 ) ]  ]
                        
        self.Steering = [ 'streering_templeLoc',(0.083,76.187,7.363),(164.923,0.576,180) ]          
        self.car = [ 'car_templeLoc',(0,15,4.582),(0,180,0) ]

        
        self.ctrol_shape = [('L_wheel_front_ctrl',9 , 40 ,(0,0,90),6,(-15,0,0)),('R_wheel_front_ctrl',9, 40,(0,0,90),13,(15,0,0)),('L_wheel_back_ctrl',9 , 40,(0,0,90),6 ,(-15,0,0)),('R_wheel_back_ctrl',9, 40,(0,0,90),13,(15,0,0)),
                        ('L_wheel_front_suspension_ctrl',10, 2,(0,90,90),6 ,(-15,0,0)),('R_wheel_front_suspension_ctrl',10, 2,(0,90,90),13 ,(15,0,0) ),('L_wheel_back_suspension_ctrl',10, 2,(0,90,90),6 ,(-15,0,0) ),('R_wheel_back_suspension_ctrl',10, 2,(0,90,90),13 ,(15,0,0) ),
                        ('streering_ctrl',10, 3,(-90,0,0),22 ,(0,0,10) ),('car_ctrl',11, 40,(0,0,0),22 ,(0,20,0) ),('car_body_ctrl' ,12,40,(0,180,0),18 ,(0,75,0) ),
                         ]
        
    def  carRig_UI(self):
        LZ_carRig_UI = 'carRig_UI'
        if mc.window(LZ_carRig_UI,ex = True):
            mc.deleteUI(LZ_carRig_UI)
            
        mc.window(LZ_carRig_UI,widthHeight=(250, 400),t=LZ_carRig_UI,menuBar = True,rtf=True,s=True)
     
        
        
        main = mc.columnLayout('LZ_Car_main',columnAttach=('both', 5), rowSpacing=10, columnWidth=250 )
        mc.button('open_craft_Win',c = lambda *args:self.openCraftWin() )
        mc.rowLayout('charactor_rowLY',numberOfColumns=2,columnWidth2=(70, 140), adjustableColumn=2, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0)])
        
        mc.text('charactor :')
        mc.textField('charactorName')
        
        
        mc.setParent('LZ_Car_main')

        
        
        mc.rowLayout('LoadCraft_rowLY',numberOfColumns=3,columnWidth3=(70, 75, 70), adjustableColumn=2, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0)])
        
        mc.text('Craft Sys :')
        mc.textField('loadCraftSys')
        mc.button('loadCraft' , c = lambda *args:self.loadCraft() )
        
        mc.setParent('LZ_Car_main')
        
        mc.button('createTemple',c = lambda *args:self.creatTemple() )
        mc.button('mirror_loc_Temple',c = lambda *args:self.mirrorTempleLoc() )
        
        mc.button('build_setting',c = lambda *args:self.createSetting() )
        
        
        
        
        mc.showWindow()
        
        
    def mirrorTempleLoc(self):
        
        for cw in self.centerWheel:
            print(cw)
            if 'L_' in cw[0]:
                suspension = str(cw[0]).replace('_wheel_','_wheelsuspension_')
                print(2)
                for L_obj in [cw[0] , suspension ]:
                    transP = mc.xform(L_obj,q=True,t=True,ws=True)
                    rotateR= mc.xform(L_obj,q=True,ro=True,ws=True)
                    print(transP)
                    print(rotateR)
                    R_obj = str(L_obj).replace('L_','R_')
                    mc.xform( R_obj , ws=True,t = (transP[0]*-1,transP[1],transP[2] ))
                    mc.xform( R_obj , ws=True,ro= (rotateR[0],rotateR[1]*-1,rotateR[2]*-1) )
                

        
        
    def loadCraft(self):
        meshSl = mc.ls(sl=True)[0]
        CraftSys = str(meshSl).split('_') 
        
        num =0
        craftName=''
        for cs in CraftSys:
            if num <2 :
                if num ==0:
                    craftName = cs

                else:
                    craftName = craftName + '_' + cs
                num = num+1
            else:
                pass
                
        mc.textField('loadCraftSys',e=True,text = craftName )
    
    def  openCraftWin(self):
        mel.eval('CraftShowUICmd')
    
    def lockAttr(self,obj = '' ,attr =['']):


        for at in attr:

                mc.setAttr(obj+'.'+ at, lock=True ,keyable = False ,channelBox = False)
    def createSetting(self):
        
        craftSysName= mc.textField('loadCraftSys',q=True,text=True)
        allSetting = self.centerWheel
        allSetting.append( self.Steering )
        allSetting.append( self.car )
        
        parentgrp = ''
        childgrp = []
        
        conparentgrp = ''
        conchildgrp = []
        
        conparentgrpZero = ''
        conchildgrpZero = []
        
        for cwl in allSetting : 
        
            suspensionTem = str(cwl[0]).replace('_wheel','_wheelsuspension')
            position = mc.xform( cwl[0] ,q=True , t=True,ws =True )
            rotation = mc.xform( cwl[0] ,q=True , ro=True,ws =True )
            
            suspension_pos = mc.xform( suspensionTem ,q=True , t=True,ws =True )
            suspension_rotation = mc.xform( suspensionTem ,q=True , ro=True,ws =True )
            
            if ('streering'   in cwl[0] ) or ('car'  in cwl[0] ):
                wheel_ctrl = str(cwl[0]).replace('_templeLoc','_ctrl')
                Suspension_ctrl = ''
                
                
                
            else:
                
            
            
                wheel_ctrl = str(cwl[0]).replace('_center_templeLoc','_ctrl')
                Suspension_ctrl = str(cwl[0]).replace('_center_templeLoc','_suspension_ctrl')
                
            grpInfo = self.createWheelSetting( wheelInfo = [ wheel_ctrl ,position,rotation ] , SuspensionInfo =[ Suspension_ctrl ,suspension_pos,suspension_rotation] ,craftSys = craftSysName )
            
            if 'car' in grpInfo[0]:
                parentgrp = grpInfo[0].replace('_ctrl_zero','_ctrl')
                conparentgrp = grpInfo[1].replace( '_zero' ,'_transInfo' )
                parentgrpZero = grpInfo[0]
                conparentgrpZero = grpInfo[1]
                
            else:
                childgrp.append(grpInfo[0])
                conchildgrp.append(grpInfo[1])
            
        mc.parent( childgrp,parentgrp )
        mc.parent( conchildgrp,conparentgrp )
        
        allgrp = 'of3d_rig'
        mc.group(em=True,n= allgrp )
        mc.parent( parentgrpZero , conparentgrpZero , allgrp )
        
        
        '''
        #             car body
        
        '''
        bodyName = 'car_body_ctrl'

        self.createTransformer( locName = bodyName,position = self.car[1] ,rotation = self.car[2],type = 'group',LocPosion = (0,0,0))
        car_body_zero = self.makeZeroGrpTwo( OrgObj = [bodyName],sufname='_zero',cenObj='',Mode=0,type = 'group',ro =True)
        
        mc.parent(  car_body_zero[0] , parentgrp )
        self.addShape_2_ctrl()
        
        
        
        '''
        
        # 控制器 加 形状和颜色
        
        '''
        
        setsInfluence = 'influence_obj'
        ctrl_all = 'all_ctrl'
        mc.sets( n =setsInfluence )
        
        if mc.objExists(ctrl_all) ==False:
            mc.sets(  n = ctrl_all )
        for csp in self.ctrol_shape:
            
            tranP = mc.xform(csp[0],q=True,t=True,ws=True)
            rotatR = mc.xform(csp[0],q=True,ro =True,ws=True)
            conName = str(csp[0])+'_consgrp'
            
            self.createTransformer( locName = conName,position = tranP ,rotation = rotatR ,type = 'group',LocPosion = (0,0,0))
            
            mc.parent( conName , csp[0] )
            if mc.nodeType(conName) == 'transform':
                mc.sets( conName ,add = setsInfluence )
                self.lockAttr(obj = conName ,attr =['v','scaleX','scaleY','scaleZ'])
            if mc.nodeType(csp[0]) == 'transform':
                mc.sets( csp[0] ,add = ctrl_all )
            
                self.lockAttr(obj = csp[0] ,attr =['v','scaleX','scaleY','scaleZ'])
            
        '''
        创建 vis 控制器
        
        '''
        
        charactorName = mc.textField('charactorName',q=True,text=True)
        zeroGrp = self.createVis( charactor = charactorName )
        grpChar = zeroGrp
        mc.move( 0 ,165,0 ,grpChar)
        mc.parent(grpChar,parentgrp )
        mc.setAttr(str(grpChar)+'.scaleX',10)
        mc.setAttr(str(grpChar)+'.scaleY',10)
        mc.setAttr(str(grpChar)+'.scaleZ',10)
        
        
    def addShape_2_ctrl(self):
        for cs in self.ctrol_shape:
            self.creatControls_command( type = cs[1] ,curName= cs[0]  ,add=True)
            self.scaleCurveHull(cs[0] ,cs[2],cs[2],cs[2])

            self.rotateCurveHull(  curveName = cs[0] ,rx = cs[3][0],ry = cs[3][1], rz = cs[3][2] ,centerP = 2 )
            self.changeCtrlColor(obj = cs[0] ,colorNum = cs[4] )
            self.moveCurveHull( curveName = cs[0],tx = cs[5][0],ty = cs[5][1], tz = cs[5][2] )
        
    def createWheelSetting(self,wheelInfo = [ '' ,(0,0,0),(0,0,0)] , SuspensionInfo =[ '' ,(0,0,0),(0,0,0)] , craftSys = ''):
        self.createTransformer( locName = wheelInfo[0],position = wheelInfo[1],rotation = wheelInfo[2] ,type='group')
        
        if SuspensionInfo[0] != '':
            self.createTransformer( locName = SuspensionInfo[0],position = SuspensionInfo[1],rotation = SuspensionInfo[2]  ,type='group')
            
            
            mc.parent( SuspensionInfo[0], wheelInfo[0])
            
            self.makeZeroGrpTwo( OrgObj = [SuspensionInfo[0] ],sufname='_zero',cenObj='',Mode=0,type = 'group',ro =True)
            self.makeZeroGrpTwo( OrgObj = [SuspensionInfo[0] ],sufname='_transInfo',cenObj='',Mode=0,type = 'group',ro =True)
        
        self.makeZeroGrpTwo( OrgObj = [ wheelInfo[0]],sufname='_zero',cenObj='',Mode=0,type = 'group',ro =True)
        self.makeZeroGrpTwo( OrgObj = [ wheelInfo[0]],sufname='_transInfo',cenObj='',Mode=0,type = 'group',ro =True)
        
        
        
        '''
        ##              con 
        '''
        congrpWheel = 'con_' + wheelInfo[0]+'_transInfo'
        
        self.createTransformer( locName = congrpWheel , position = wheelInfo[1],rotation =wheelInfo[2]  ,type='group')
        
        if SuspensionInfo[0] != '':
            conSuspensionInfo = 'con_' + SuspensionInfo[0]+'_transInfo'
            self.createTransformer( locName = conSuspensionInfo , position = SuspensionInfo[1],rotation = SuspensionInfo[2]  ,type='group')
            mc.parent( conSuspensionInfo, congrpWheel)
            self.makeZeroGrpTwo( OrgObj = [conSuspensionInfo ],sufname='zero',cenObj='',Mode=1,type = 'group',ro =True)
        
        
        
        
        self.makeZeroGrpTwo( OrgObj = [ congrpWheel ],sufname='zero',cenObj='',Mode=1,type = 'group',ro =True)
        
        
        mc.connectAttr( str( congrpWheel )+'.translate' ,str( wheelInfo[0] )+'_transInfo.translate')
        mc.connectAttr( str( congrpWheel )+'.rotate' ,str( wheelInfo[0] )+'_transInfo.rotate')
        
        if SuspensionInfo[0] != '':
            mc.connectAttr( str( conSuspensionInfo )+'.translate' ,str( SuspensionInfo[0] )+'_transInfo.translate')
            mc.connectAttr( str( conSuspensionInfo )+'.rotate' ,str( SuspensionInfo[0] )+'_transInfo.rotate')
        
        '''
        ##              约束
        '''
        if craftSys != '':
        
            if 'streering' in wheelInfo[0]:
                SteeringMesh = craftSys + '_SteeringWheelMeshTransform'
                if mc.objExists( SteeringMesh ) ==True:
                    mc.parentConstraint( SteeringMesh , congrpWheel ,mo=True )
            elif 'car' in wheelInfo[0]:
                SteeringMesh = craftSys + '_CarBodyMeshTransform'
                if mc.objExists( SteeringMesh ) ==True:
                    mc.parentConstraint( SteeringMesh , congrpWheel ,mo=True )
            
            
            else:
                dirFB = ''
                dirLR = ''
                if 'front' in wheelInfo[0]:
                    dirFB = 'F'
                else:
                    dirFB = 'B'
                
                if 'L_' in wheelInfo[0]:
                    dirLR = 'L'
                else:
                    dirLR = 'R'
                
                wheelMesh = craftSys+'_WheelMesh_' + dirFB + dirLR +'Transform'
                suspensionMesh = craftSys + '_WheelCenterSuspensionMesh_' + dirFB + dirLR +'Transform'
                
                if mc.objExists( wheelMesh ) ==True:
                    mc.parentConstraint( wheelMesh , congrpWheel ,mo=True)
 
                if mc.objExists( suspensionMesh ) ==True :
                    mc.parentConstraint( suspensionMesh , conSuspensionInfo ,mo=True )
                
                
        return (str( wheelInfo[0] )+'_zero',str(congrpWheel).replace('_transInfo','_zero'))
        
        
    def creatTemple(self):
        for cwl in self.centerWheel:
         
            self.createWheelTemple( wheelInfo = cwl )
        
        
        Steering = self.Steering
        self.createTransformer( locName = Steering[0],position = Steering[1],rotation = Steering[2] ,type='locator')
        
        body = self.car
        self.createTransformer( locName = body[0],position = body[1],rotation = body[2] ,type='locator')
        
    def createWheelTemple(self,wheelInfo = ['',(0,0,0)]  ):
        Suspension = str(wheelInfo[0]).replace('_wheel','_wheelsuspension')
        
        self.createTransformer( locName = wheelInfo[0],position = wheelInfo[1],rotation = ( 0,180,0) ,type='locator')
        self.createTransformer( locName = Suspension,position = wheelInfo[1],rotation = ( 0,180,0) ,type='locator',LocPosion = (0,3,0) )
        mc.parent( Suspension , wheelInfo[0] )
    
    
        

    
    def createTransformer(self,locName = '',position = ( 0,0,0),rotation = ( 0,0,0) ,type = 'locator',LocPosion = (0,0,0)):
        if type =='locator': 
            mc.spaceLocator(  n = locName ,p = LocPosion )
        elif type =='group':
            mc.group( em = True , n= locName)
        mc.move( position[0], position[1],position[2], locName )
        mc.rotate( rotation[0], rotation[1],rotation[2], locName )
        
    def makeZeroGrpTwo(self,OrgObj = [''],sufname='zero',cenObj='',Mode=0,type = 'group',ro =True):    #  type = 'group'   or type  ='joint'
    #   mode == 1:  replace;  mode == 0:  add  
        seleobj=mc.ls(sl=True)
        group_all =[]

        for i in OrgObj:
            if cenObj=='':
                cenParent=i
            else:
                cenParent=cenObj
            if Mode==0:
                groupname=str(i)+sufname
            if Mode==1:
                regName=str(i).split('_')
                groupname=str(i).replace(regName[-1],sufname)
                
            if type == 'group':
                mc.group(n=groupname,em=True)
            elif type == 'joint':
                mc.select(cl=True)
                mc.joint( n =groupname )
            parent=mc.listRelatives(i,p=True)
            mc.pointConstraint(cenParent,groupname,mo=False,n='needDeleteConstriant',w=1)
            mc.delete('needDeleteConstriant')
            if ro == True:
                mc.orientConstraint(cenParent,groupname,mo=False,n='needDeleteConstriant',w=1)
                
                mc.delete('needDeleteConstriant')
                
                if type =='joint':
                    self.frozeen_jnt_Transform( groupname )
            mc.parent(i,groupname)
            if parent==None:
                pass
            else:
                mc.parent(groupname,parent)
                
            group_all.append(groupname)
        mc.select(OrgObj)
        return(group_all)
        
    '''
        =========================================================
        ||                                                     ||
        ||控制器 部分 的 commands                              ||
        ||the part of control  shapes                          ||
        ||                                                     ||
        =========================================================
    '''   
                    
    
    
    def creatControls_command(self,type = 1 ,curName='',add=True):
        if type==1:
            pointInfo=[(-2,0, 0),(-2, 0, -1),( 0, 0 ,-1),( 0, 0, -2),( 2, 0 ,0 ),( 0, 0, 2),( 0 ,0 ,1),( -2, 0, 1),( -2, 0, 0)]
            pioint_K = [0,1,2,3,4,5,6,7,8]
            degreee = 1
        if type ==2 :   ###  facial ctrl 
            pointInfo = [(-0.5, 0.5, -0.5), (-0.5, -0.5, -0.5),( -0.5, -0.5, 0.5),( -0.5, 0.5, 0.5),(-0.5, 0.5, -0.5),( 0.5, 0.5 ,-0.5),( 0.5, 0.5, 0.5 ),( -0.5 ,0.5 ,0.5),( -0.5 ,-0.5, 0.5),( 0.5, -0.5, 0.5 ),( 0.5 ,0.5 ,0.5 ),( 0.5, 0.5, -0.5),( 0.5, -0.5, -0.5),( 0.5, -0.5, 0.5),( 0.5, -0.5,-0.5),(-0.5, -0.5, -0.5)]
            pioint_K = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
            degreee = 1
        
        if type == 3:  ##  eye ctrl
            pointInfo = [(-0.273501,0.398437,0),( 0.279265, 0.399227, 0),(0.284735, 0.4 ,0 ),( 0.287565, 0.405343 ,0 ),(0.334556 ,0.514181, 0 ),(0.553402, 0.840365 ,0 ),(1.2 ,1.108194, 0 ),(1.983612, 0.783612, 0 ),( 2.308194 ,0 ,0 ),(1.983612, -0.783612, 0),( 1.2, -1.108194, 0 ),(0.553402, -0.840365, 0 ),(0.334556 ,-0.514181, 0 ),( 0.28798, -0.40954 ,0 ),( 0.284735, -0.4 ,0 ),(0.27551, -0.400633 ,0 ),( -0.279436, -0.400321, 0 ),(-0.284735 ,-0.4,0 ),( -0.286778, -0.405624 ,0),( -0.334556 ,-0.514181, 0 ),( -0.553402, -0.840365 ,0 ),( -1.2 ,-1.108194 ,0 ),(-1.983612, -0.783612 ,0 ),( -2.308194 ,0 ,0 ),( -1.983612 ,0.783612, 0 ),( -1.2 ,1.108194 ,0 ),( -0.553402, 0.840365, 0 ),( -0.334556 ,0.514181, 0 ),( -0.289495, 0.408848 ,0 ),( -0.284735 ,0.4 ,0 ),( -0.273501, 0.398437, 0)]
            pioint_K = [0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,28,28]
            degreee = 3
            
        if type == 4:  ##  eye aim sec ctrl
            pointInfo = [(-1, 0, 0 ),( 0 ,0 ,0 ),(0 ,1, 0 ),( 0, 0 ,0 ),( 1, 0, 0 ),( 0, 0, 0),( 0 ,-1, 0) ]
            pioint_K = [0,1,2,3,4,5,6]
            degreee = 1
        if type == 5:  ##  circle 
            pass

            
            
        if type == 6:  ##  
            pass
        
        if type == 7:
            pointInfo = [(-1 ,0 ,0),( 1, 0, 0),( 0, 0 ,0),( 0, 0, 1),( 0, 0 ,-1 ),( 0, 0, 0),( 0 ,1 ,0 ),( 0 ,-1 ,0 ) ]
            pioint_K = [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ]
            degreee = 1
            
        if type == 8:
            pointInfo = [ (-1 ,4 ,0),( 1 ,4 ,0),( 1, 1, 0 ),( 4 ,1 ,0),( 4 ,-1, 0),( 1, -1 ,0 ),( 1, -4 ,0),(-1, -4 ,0 ),( -1 ,-1 ,0 ),( -4 ,-1, 0),( -4 ,1, 0 ),( -1, 1, 0),( -1, 4 ,0 ) ]
            pioint_K = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8, 9 , 10 , 11 , 12 ]
            degreee = 1
        
        if type == 9:
            pointInfo = [( 0 ,0 ,0.492662),( -0.0209175, 0 ,0.440895),( -0.0627526, 0, 0.476654 ),( -0.124432 ,0 ,0.464385 ),( -0.183981 ,0 ,0.44417 ),( -0.240383 ,0 ,0.416356 ),( -0.292672 ,0 ,0.381418),( -0.339953, 0, 0.339953 ),( -0.381418, 0 ,0.292672),( -0.416356, 0,0.240383 ),( -0.44417, 0 ,0.183981),( -0.464385 ,0 ,0.124432 ),( -0.476654 ,0 ,0.0627526 ),( -0.423016 ,0, 0 ),( -0.476654 ,0 ,-0.0627526 ),( -0.464385 ,0 ,-0.124432 ),( -0.44417 ,0 ,-0.183981 ),( -0.416356 ,0 ,-0.240383),( -0.381418, 0 ,-0.292672 ),( -0.339953, 0 ,-0.339953 ),( -0.292672, 0 ,-0.381418 ),( -0.240383, 0, -0.416356 ),(-0.183981 ,0 ,-0.44417 ),( -0.124432, 0 ,-0.464385 ),( -0.0627526 ,0 ,-0.476654 ),( 0, 0 ,-0.423016),( 0.0627526, 0 ,-0.476654 ),( 0.124432, 0 ,-0.464385 ),( 0.183981, 0, -0.44417),( 0.240383 ,0 ,-0.416356 ),( 0.292672, 0 ,-0.381418 ),( 0.339953 ,0 ,-0.339953 ),( 0.381418, 0, -0.292672 ),( 0.416356 ,0 ,-0.240383),( 0.44417 ,0, -0.183981 ),( 0.464385 ,0 ,-0.124432 ),( 0.476654, 0, -0.0627526),( 0.423016, 0 ,0 ),( 0.476654, 0 ,0.0627526 ),( 0.464385 ,0 ,0.124432 ),( 0.44417, 0 ,0.183981),( 0.416356, 0 ,0.240383 ),( 0.381418, 0 ,0.292672 ),(0.339953, 0 ,0.339953),( 0.292672 ,0 ,0.381418 ),( 0.240383, 0 ,0.416356 ),( 0.183981 ,0 ,0.44417 ),( 0.124432 ,0 ,0.464385 ),( 0.0627526, 0 ,0.476654 ),( 0.0209175, 0 ,0.440895 ),( 0 ,0 ,0.492662 ),( -0.0290887 ,0 ,0.5 ),( -0.087266, 0 ,0.49491),( -0.17188 ,0 ,0.472238 ),( -0.251272 ,0 ,0.435217 ),( -0.32303, 0 ,0.384972 ),( -0.384972 ,0 ,0.32303 ),( -0.435217 ,0, 0.251272 ),( -0.472238, 0 ,0.17188 ),( -0.49491 ,0 ,0.087266 ),( -0.502545, 0 ,0 ),( -0.49491 ,0 ,-0.087266 ),( -0.472238 ,0, -0.17188),( -0.435217 ,0, -0.251272 ),( -0.384972, 0 ,-0.32303 ),( -0.32303, 0, -0.384972 ),( -0.251272 ,0, -0.435217 ),( -0.17188 ,0, -0.472238 ),( -0.087266 ,0 ,-0.49491 ),( 0 ,0 ,-0.502545 ),( 0.087266 ,0 ,-0.49491),( 0.17188 ,0, -0.472238 ),( 0.251272 ,0, -0.435217),( 0.32303 ,0 ,-0.384972 ),( 0.384972 ,0 ,-0.32303),( 0.435217 ,0, -0.251272 ),( 0.472238 ,0, -0.17188 ),( 0.49491 ,0 ,-0.087266 ),( 0.502545 ,0 ,0),( 0.49491, 0 ,0.087266 ),( 0.472238, 0 ,0.17188 ),( 0.435217 ,0 ,0.251272 ),( 0.384972 ,0 ,0.32303 ),( 0.32303 ,0 ,0.384972 ),( 0.251272 ,0 ,0.435217 ),( 0.17188, 0 ,0.472238 ),( 0.087266 ,0 ,0.49491 ),( 0.0290887, 0 ,0.5 ),( 0 ,0 ,0.492662)]    
            pioint_K = [ 0 , 0 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 86 , 86  ]
            degreee =3
            
        if type == 10:    
            pointInfo =[(4, 0, 0 ),( 3 ,0 ,2),( 0 ,0 ,3 ),( -3 ,0 ,2 ),( -4 ,0 ,0 ),( -4, 0, 0 ),( -6 ,0, 0),( -6 ,0 ,0 ),( -5 ,0, 3 ),( -2 ,0 ,5 ),( 0 ,0 ,5 ),( 2 ,0 ,5 ),( 5 ,0 ,3 ),( 6 ,0 ,0 ),( 6 ,0 ,0 ),( 4 ,0, 0)]
        
            pioint_K = [ 0 , 0 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 13 , 13]
            degreee =3
        if type == 11:    
            pointInfo =[(0 ,0, -5 ),( 2 ,0, -5 ),( 3, 0 ,-4 ),( 3 ,0, -1 ),(2, 0, 0 ),( 2 ,0 ,1 ),( 3 ,0 ,3 ),( 3 ,0 ,5 ),( 2 ,0 ,6 ),( 0 ,0 ,6 ),( -2, 0, 6 ),( -3, 0 ,5 ),( -3 ,0 ,3 ),( -2 ,0 ,1 ),( -2 ,0 ,0 ),( -3 ,0, -1 ),( -3, 0 ,-4 ),( -2 ,0 ,-5 ),( 0, 0, -5)]
        
            pioint_K = [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 ]
            degreee =1
        
        if type == 12:    
            pointInfo =[(-2.0425, 1.067262, -0.267548 ),( -1.90608 ,1.604237, -0.291831 ),(-1.458906 ,2.07659, -0.291831),( -0.838961 ,2.38217 ,-0.291831 ),( 0, 2.472737 ,-0.291831),( 0.838961 ,2.38217 ,-0.291831 ),( 1.458906, 2.07659, -0.291831),( 1.90608 ,1.604237 ,-0.291831 ),( 2.0425 ,1.067262 ,-0.267548 ),( 2.0425, 1.067262, -0.267548 ),( 2.027141 ,1.067262 ,0.828746 ),( 2.36081, 1.067262 ,2.186062 ),( 1.992973, 1.067262 ,4.579428 ),( 0.476366, 1.067262, 4.587467 ),( 0, 0.893449, 4.84523 ),( -0.476366 ,1.067262, 4.587467 ),( -1.992973 ,1.067262 ,4.579428 ),( -2.36081 ,1.067262 ,2.186062 ),( -2.027141 ,1.067262, 0.828746 ),( -2.0425, 1.067262, -0.267548 ),( -2.316573, 1.067262 ,-2.016397 ),( -2.355726 ,1.067262 ,-3.127629 ),( -2.303522, 1.067262 ,-3.323396 ),( -1.664017 ,1.067262 ,-3.745478 ),( -0.907053 ,1.067262 ,-3.778298 ),( 0 ,1.324136 ,-3.778298 ),( 0.907053 ,1.067262 ,-3.778298 ),( 1.664017 ,1.067262, -3.745478 ),( 2.303522, 1.067262, -3.323396 ),( 2.355726 ,1.067262, -3.127629 ),( 2.316573, 1.067262 ,-2.016397 ),( 2.0425, 1.067262 ,-0.267548 ),( 2.027141, 1.067262, 0.828746 ),( 2.36081 ,1.067262 ,2.186062 ),( 1.992973, 1.067262 ,4.579428 ),( 0.476366 ,1.067262 ,4.587467 ),( 0, 0.893449 ,4.84523 ),( 0 ,0.893449 ,4.84523 ),( 0 ,0.893449 ,4.84523 ),( 0 ,1.96364 ,3.699991 ),( 0 ,2.289918 ,2.186062 ),( 0 ,2.316021 ,0.828746 ),( 0 ,2.472737 ,-0.291831 ),( 0 ,2.733656, -2.016397 ),( 0 ,2.77281, -2.708107 ),( 0 ,2.720605 ,-2.903873),( 0, 2.081101, -3.517276 ),( 0, 1.324136, -3.778298)]
        
            pioint_K = [0 , 0 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 45 , 45  ]
            degreee =3
        
        
        if add == True:
            ctrlAdd = str(curName) + '_temple'
            if type == 5 :
                mc.circle(c=(0,0,0),nr=(0,1,0),sw=360,r=1,d=3,ut = 0,tol= 0.01,s=8,ch=False,n=ctrlAdd)
            elif type == 6 :
            
                mc.circle(c=(0,0,0),nr=(0,1,0),sw=360,r=1,d=1,ut = 0,tol= 0.01,s=4,ch=False,n=ctrlAdd)
                
            else:
            
                mc.curve(d = degreee ,p = pointInfo,k= pioint_K ,n=ctrlAdd )    
            Templeshape=mc.listRelatives(ctrlAdd,s=True)
            mc.parent(Templeshape,curName,add=True,s=True)
            mc.delete(ctrlAdd)
            CtrlShapeAdd = mc.rename(Templeshape,str(curName)+'Shape')
            
        else:
            if type == 5 :
                mc.circle(c=(0,0,0),nr=(0,1,0),sw=360,r=1,d=3,ut = 0,tol= 0.01,s=8,ch=False,n=curName)
            elif type == 6 :
            
                mc.circle(c=(0,0,0),nr=(0,1,0),sw=360,r=1,d=1,ut = 0,tol= 0.01,s=4,ch=False,n=curName)
        
            else:
                mc.curve(d = degreee ,p = pointInfo,k= pioint_K ,n = curName )  
    def moveCurveHull(self,curveName = '',tx = 0,ty = 0, tz = 0 ):

        curveshapes=mc.listRelatives(curveName,s=True)
        for curveshape  in curveshapes:
            spans=mc.getAttr(str(curveshape)+'.spans')
            degree=mc.getAttr(str(curveshape)+'.degree')
            pointsMounts=spans+degree
        
            mc.move( tx,ty,tz,str(curveshape) + '.cv[0:' + str(pointsMounts)  +']' ,os=True, r=True )
        
    def rotateCurveHull(self, curveName = '',rx = 0,ry = 0, rz = 0 ,centerP = 1 ):
        curveshapes=mc.listRelatives(curveName,s=True)
        
        cvAllX=[]
        cvAllY=[]
        cvAllZ=[]

        for curveshape in curveshapes:
            spans=mc.getAttr(str(curveshape)+'.spans')
            degree=mc.getAttr(str(curveshape)+'.degree')
            pointsMounts=spans+degree

            for i in range(pointsMounts):

                pointcvPos=mc.xform(str(curveshape)+'.cv['+str(i)+']',q=True,t=True,ws=True)

                cvAllX.append(pointcvPos[0])
                cvAllY.append(pointcvPos[1])
                cvAllZ.append(pointcvPos[2])
                
        pointCVposXMin=cvAllX[0]
        pointCVposYMin=cvAllY[0]
        pointCVposZMin=cvAllZ[0]
        
        pointCVposXMax=cvAllX[0]
        pointCVposYMax=cvAllY[0]
        pointCVposZMax=cvAllZ[0]
        


        for k in range(len(cvAllX)):
            pointCVposXMin=min(pointCVposXMin,cvAllX[k])
            pointCVposXMax=max(pointCVposXMax,cvAllX[k])
            
            pointCVposYMin=min(pointCVposYMin,cvAllY[k])
            pointCVposYMax=max(pointCVposYMax,cvAllY[k])
            
            pointCVposZMin=min(pointCVposZMin,cvAllZ[k])
            pointCVposZMax=max(pointCVposZMax,cvAllZ[k])
        
        centerPivetX=(pointCVposXMin+pointCVposXMax)/2
        centerPivetY=(pointCVposYMin+pointCVposYMax)/2
        centerPivetZ=(pointCVposZMin+pointCVposZMax)/2
        
        if centerP==1:
            centerPivet=[centerPivetX,centerPivetY,centerPivetZ]
            
        else:
            centerPivet = mc.xform(curveName , q=True ,t =True,ws=True)
        mc.rotate( rx,ry,rz,str(curveshape) + '.cv[0:' + str(pointsMounts)  +']' ,os=True, r=True,p = centerPivet )
            
        
    def scaleCurveHull(self,curvename,scalX,scalY,scalZ):
        curveshapes=mc.listRelatives(curvename,s=True)
        
        cvAllX=[]
        cvAllY=[]
        cvAllZ=[]

        for curveshape in curveshapes:
            spans=mc.getAttr(str(curveshape)+'.spans')
            degree=mc.getAttr(str(curveshape)+'.degree')
            pointsMounts=spans+degree

            for i in range(pointsMounts):

                pointcvPos=mc.xform(str(curveshape)+'.cv['+str(i)+']',q=True,t=True,ws=True)

                cvAllX.append(pointcvPos[0])
                cvAllY.append(pointcvPos[1])
                cvAllZ.append(pointcvPos[2])
                
        pointCVposXMin=cvAllX[0]
        pointCVposYMin=cvAllY[0]
        pointCVposZMin=cvAllZ[0]
        
        pointCVposXMax=cvAllX[0]
        pointCVposYMax=cvAllY[0]
        pointCVposZMax=cvAllZ[0]
        


        for k in range(len(cvAllX)):
            pointCVposXMin=min(pointCVposXMin,cvAllX[k])
            pointCVposXMax=max(pointCVposXMax,cvAllX[k])
            
            pointCVposYMin=min(pointCVposYMin,cvAllY[k])
            pointCVposYMax=max(pointCVposYMax,cvAllY[k])
            
            pointCVposZMin=min(pointCVposZMin,cvAllZ[k])
            pointCVposZMax=max(pointCVposZMax,cvAllZ[k])
        
        centerPivetX=(pointCVposXMin+pointCVposXMax)/2
        centerPivetY=(pointCVposYMin+pointCVposYMax)/2
        centerPivetZ=(pointCVposZMin+pointCVposZMax)/2
        
        centerPivet=[centerPivetX,centerPivetY,centerPivetZ]
            
        #mc.select(str(curvename)+'.cv[0:'+str((pointsMounts-1))+']')
        
        for curveshape in curveshapes:
            
            spans=mc.getAttr(str(curveshape)+'.spans')
            degree=mc.getAttr(str(curveshape)+'.degree')
            pointsMounts=spans+degree
            
            
            cv = str(curveshape)+'.cv[0:'+str((pointsMounts-1))+']'
            mc.scale(scalX,scalY,scalZ,cv,r=True,p=centerPivet)
            
    def normalizeHull(self,curvename):
        curveshapes=mc.listRelatives(curvename,s=True)
        
        cvAllX=[]
        cvAllY=[]
        cvAllZ=[]

        for curveshape in curveshapes:
            spans=mc.getAttr(str(curveshape)+'.spans')
            degree=mc.getAttr(str(curveshape)+'.degree')
            pointsMounts=spans+degree

            for i in range(pointsMounts):

                pointcvPos=mc.xform(str(curveshape)+'.cv['+str(i)+']',q=True,t=True,ws=True)

                cvAllX.append(pointcvPos[0])
                cvAllY.append(pointcvPos[1])
                cvAllZ.append(pointcvPos[2])
                
        pointCVposXMin=cvAllX[0]
        pointCVposYMin=cvAllY[0]
        pointCVposZMin=cvAllZ[0]
        
        pointCVposXMax=cvAllX[0]
        pointCVposYMax=cvAllY[0]
        pointCVposZMax=cvAllZ[0]
        


        for k in range(len(cvAllX)):
            pointCVposXMin=min(pointCVposXMin,cvAllX[k])
            pointCVposXMax=max(pointCVposXMax,cvAllX[k])
            
            pointCVposYMin=min(pointCVposYMin,cvAllY[k])
            pointCVposYMax=max(pointCVposYMax,cvAllY[k])
            
            pointCVposZMin=min(pointCVposZMin,cvAllZ[k])
            pointCVposZMax=max(pointCVposZMax,cvAllZ[k])
        
        centerPivetX=(pointCVposXMin+pointCVposXMax)/2
        centerPivetY=(pointCVposYMin+pointCVposYMax)/2
        centerPivetZ=(pointCVposZMin+pointCVposZMax)/2
        
        centerPivet=[centerPivetX,centerPivetY,centerPivetZ]
        

        
        position = mc.xform( curvename ,q=True ,t=True,ws =True)
        for curveshape in curveshapes:
            
            spans=mc.getAttr(str(curveshape)+'.spans')
            degree=mc.getAttr(str(curveshape)+'.degree')
            pointsMounts=spans+degree
            
            
            cv = str(curveshape)+'.cv[0:'+str((pointsMounts-1))+']'
            mc.move( ( position[0] -centerPivet[0] ),( position[1] -centerPivet[1]   ),(  position[2]-centerPivet[2] ), cv , r=True)
    
    
    
    def changeCtrlColor(self,obj = '',colorNum = 1 ):
            shapes = mc.listRelatives(obj,s=True)
            for sp in shapes:
                mc.setAttr( str(sp) +'.overrideEnabled' , 1)
                mc.setAttr( str(sp) +'.overrideColor' , colorNum )
                